/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Loginform.java
 *
 * Created on Mar 17, 2011, 10:45:14 PM
 */

package Main;


import AdminExpo.changeInfor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
 *
 * @author Mai Lan
 */
public class Loginform extends javax.swing.JFrame {
         

   

   
     
    /** Creates new form Loginform */
    public Loginform() {
       
        initComponents();
        ExpoManagerMain.Connect();
        setTitle("Login Admin");
    

    }
    public void loginAdd() throws SQLException{
       
        boolean check=this.ValLoginAd();
        if(check==true){


            boolean flag=true;
            String sqlLG="";
            String accAd=txtAcc.getText().trim();
            String passAd=new String(passPW.getPassword());
//            if(radAdmin.isSelected()==true){
                 sqlLG="select * from AdminExpo  where AccountAd ='"+accAd+"' and PassWordAd ='"+passAd+"';";

//            }else if(radExhi.isSelected()==true){
//                 sqlLG="select * from Exhibitor  where AccountAd ='"+accAd+"' and PassWordAd ='"+passAd+"';";
//            }
            Statement stLG=ExpoManagerMain.conn.createStatement();
            ResultSet rsLG=stLG.executeQuery(sqlLG);
            if(!rsLG.next()){
                JOptionPane.showConfirmDialog(null, "Admin name or password is invalid \nAdmin not active .Please try agian","Login Fails",JOptionPane.ERROR_MESSAGE);
                flag=false;

            }
            if(flag==true){
                
               changeInfor.id=rsLG.getString("Id");

               MainFrame.id=rsLG.getString("Id");
               MainFrame.power=rsLG.getString("powerAd");
               MainFrame objA=new MainFrame();

                

               objA.setVisible(true);
               dispose();
               
            }
        }
       
            
             
        
    }
    public boolean  ValLoginAd(){
        if(txtAcc.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Enter Account!!");
            txtAcc.requestFocus();
            return false;
        }if(passPW.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Enter Password!!");
            passPW.requestFocus();
            return false;
        }
        return true;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtAcc = new javax.swing.JTextField();
        passPW = new javax.swing.JPasswordField();
        btnLg = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        btnConfig = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconExpo/kuser.png"))); // NOI18N

        jLabel2.setBackground(new java.awt.Color(153, 153, 255));
        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 18));
        jLabel2.setText("Expo Management System");

        jLabel3.setText("Enter your password and account");

        jLabel4.setText("Account");

        jLabel5.setText("Password");

        txtAcc.setText("mailan");

        passPW.setText("mailan");

        btnLg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconExpo/login.png"))); // NOI18N
        btnLg.setText("Login");
        btnLg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLgActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconExpo/001_02.png"))); // NOI18N
        jButton2.setText("Exit");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        btnConfig.setFont(new java.awt.Font("Tahoma", 1, 10));
        btnConfig.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconExpo/config.png"))); // NOI18N
        btnConfig.setText("Config Server");
        btnConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfigActionPerformed(evt);
            }
        });
        jToolBar1.add(btnConfig);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(btnLg, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(22, 22, 22)
                                    .addComponent(jLabel4))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(20, 20, 20)
                                    .addComponent(jLabel5)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(passPW)
                                .addComponent(txtAcc, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(49, 49, 49)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtAcc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(passPW, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton2, 0, 0, Short.MAX_VALUE)
                            .addComponent(btnLg, javax.swing.GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE))
                        .addGap(28, 28, 28)
                        .addComponent(jLabel3))
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @SuppressWarnings("static-access")
    private void btnLgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLgActionPerformed
        if(ExpoManagerMain.conn==null){
             JOptionPane.showConfirmDialog(null, "please click button config! And fill information Config","Warning",JOptionPane.OK_CANCEL_OPTION);
            
//             new ExpoManagerMain().setVisible(true);
//             this.dispose();
             btnConfig.requestFocus();
             btnLg.setEnabled(false);
             return;
        }else{
            
            try {
                this.loginAdd();
            } catch (SQLException ex) {
                Logger.getLogger(Loginform.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_btnLgActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void btnConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfigActionPerformed
        new ExpoManagerMain().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnConfigActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Loginform().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JButton btnConfig;
    private javax.swing.JButton btnLg;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JPasswordField passPW;
    private javax.swing.JTextField txtAcc;
    // End of variables declaration//GEN-END:variables





}
